package com.base.cn.platform.os.controller.qa;

import com.base.cn.platform.os.common.utils.result.ResultUtil;
import com.base.cn.platform.os.controller.cmmon.ApiBaseController;
import com.base.cn.platform.os.service.course.qa.question.QaQuestionService;
import com.base.cn.platform.os.service.course.qa.record.QaGainAttendRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

/**
 * 用户的问答接口
 *
 * @author s.li
 * @create 2018-09-05-14:18
 */
@RestController
@RequestMapping("/api/qa")
public class ApiUserQaController extends ApiBaseController {

    @Autowired
    private QaQuestionService qaQuestionService;
    @Autowired
    private QaGainAttendRecordService qaGainAttendRecordService;

    /**
     *
     * @param userId 用户ID
     * @param queryType 查询类型：  1我提问的(免费)，2我回答的，3我的提问（付费），4我的围观
     * @param currentPage 页码
     * @return Map<String,Object>
     */
    @RequestMapping("/findMyQuestionList")
    public Map<String,Object> findMyQuestionList(@RequestParam("userId") BigDecimal userId,
                                                 @RequestParam("queryType") int queryType,
                                                 @RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage){
        Map<String,Object> qaDataMap = qaQuestionService.queryMyQuestionList(currentPage,10,userId,
                queryType,false,true,false,false,false,false,false);
        return ResultUtil.SUCCESS(qaDataMap);
    }

    /**
     * 查询用户的收益详情列表
     *
     * @param userId 用户id
     * @param currentPage
     * @return
     */
    @RequestMapping("/queryMyEarningList")
    public Map<String,Object> queryMyEarningList(@RequestParam("userId") BigDecimal userId,
                                                 @RequestParam(value = "currentPage",required = false,defaultValue = "1") int currentPage){

        Map<String, Object> param = new HashMap<>();
        param.put("receiptorId",userId);
        param.put("userType",3);
        Map<String, Object> attendRecord = qaGainAttendRecordService.queryGainAttendRecordListPage(currentPage, param, true, true);
        //用户所有收益
        double allUserQaEarning = qaGainAttendRecordService.getUserQaEarning(param);
        attendRecord.put("allUserQaEarning",allUserQaEarning);
        //用户可提现收益
        param.put("status",1);
        double userAbleQaEarning = qaGainAttendRecordService.getUserQaEarning(param);
        attendRecord.put("userAbleQaEarning",userAbleQaEarning);
        return ResultUtil.SUCCESS(attendRecord);
    }

    /**
     * 问答收益提取到我的账户
     *
     * @param userId
     * @return
     */
    @RequestMapping("/extractEarning")
    public Map<String,Object> extractEarning(@RequestParam("userId") BigDecimal userId){
        Map<String ,Object> params = new HashMap<>();
        params.put("receiptorId",userId);
        params.put("userType",3);
        Map<String, Object> result = qaGainAttendRecordService.extractEarning(params);
        return ResultUtil.SUCCESS(result);
    }

}
